<template>
  <div class="employees">
    <el-card class="btn">
      <el-button type="primary">导入</el-button>
      <el-button type="primary">+新增员工</el-button>
    </el-card>
    <el-card>
      <el-table :data="list">
        <el-table-column label="序号">
          <template v-slot="{ $index }">
            <div>
              {{ (page.page - 1) * page.size + $index + 1 }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="姓名" prop="username" />
        <el-table-column label="手机号" prop="mobile" />
        <el-table-column label="工号" prop="workNumber" />
        <el-table-column label="聘用形势" prop="formOfEmployment" />
        <el-table-column label="部门" prop="departmentName" />
        <el-table-column label="入职时间" prop="timeOfEntry" />
        <!-- <el-table-column label="是否在职" /> -->
        <el-table-column label="状态" prop="enableState" />
        <el-table-column label="操作" width="300" fixed="rigth">
          <template>
            <div>
              <el-button type="text">查看</el-button>
              <el-button type="text">转正</el-button>
              <el-button type="text">调岗</el-button>
              <el-button type="text">离职</el-button>
              <el-button type="text">角色</el-button>
              <el-button type="text">删除</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="page">
        <el-pagination
          :current-page="page.page"
          :page-size="page.size"
          :total="page.total"
          :page-sizes="[1, 5, 10, 20, 200, 300, 400]"
          layout="total,sizes,prev,pager,next,jumper"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
        />
      </div>
    </el-card>
  </div>
</template>

<script>
import { sysUser } from '@/api/employees.js'
export default {
  data() {
    return {
      list: [{}],
      page: {
        total: 100,
        page: 1,
        size: 1
      }
    }
  },
  created() {
    this.getData()
  },

  methods: {
    async getData() {
      const res = await sysUser(this.page)
      // 原始数据转换
      res.data.rows.forEach((item) => {
        item.formOfEmployment = this.formatter(
          null,
          null,
          item.formOfEmployment
        )
      })
      this.list = res.data.rows
      this.page.total = res.data.total
      console.log('员工列表', res)
    },
    handleSizeChange(size) {
      this.page.size = size
      this.page.page = 1
      this.getData()
    },
    handleCurrentChange(page) {
      this.page.page = page
      this.getData()
    }
  }
}
</script>

<style lang="scss" scoped>
.employees {
  padding: 15px;
  .btn {
    text-align: right;
    margin-bottom: 15px;
  }
  .page {
    padding-top: 30px;
    text-align: right;
  }
}
</style>
